<?php
namespace application\modules\examples\controllers;

use system\core\Controller;
use system\libraries\FormValidation;

class Forms extends Controller
{
    public function index() 
    {
        $formValidation = new FormValidation();
        
        $formValidation->rules('first_name', 'lang:first_name', 'required|min_length[3]');
        $formValidation->rules('last_name', 'lang:last_name', 'required|min_length[3]');
        $formValidation->rules('email', 'lang:email', 'required|is_email');
        $formValidation->rules('gender', 'lang:gender', 'required');
        
        // Run Form 1
        if ( isset($_POST['btnForm1']) )
        {
            if ( $formValidation->run() )
            {
                // Form 1 is success, do something...
                echo 'Form 1 success!';
            }
        }
        
        // Set rules for Form 2
        $formValidation2 = new FormValidation('form2'); // Note the parameter
        
        $formValidation2->rules('username', 'lang:username', 'required|min_length[4]');
        $formValidation2->rules('password', 'lang:password', 'required|min_length[6]');
        $formValidation2->rules('password_confirm', 'lang:password_confirm', 'matches[password]');
        
        // Run Form 2
        if ( isset($_POST['btnForm2']) )
        {
            if ( $formValidation2->run() )
            {
                // Form 2 is success, do something...
                echo 'Form 2 success!';
            }
        }
    }
    
    public function callback_checkGender( $str )
    {
        $valid = array('male', 'female');
        if ( in_array($str, $valid) )
        {
            return TRUE;
        }
        
        return 'lang:callback_checkGender'; // You can put any key here :)
    }
}

/* End of file Forms.php */
